package com.shijun.tankwar;

import android.os.Bundle;
import android.widget.RelativeLayout;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";
    private RelativeLayout contentLayout;
    private ControlMoveView controlMoveView;
    private ControlOrientationView controlOrientationView;
    private ContentView contentView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        contentView = findViewById(R.id.activity_main_content_cv);
        int width = getWindowManager().getDefaultDisplay().getWidth();
        int height = getWindowManager().getDefaultDisplay().getHeight();

        controlMoveView = new ControlMoveView(this,getResources().getDimensionPixelSize(R.dimen.x40),0, getResources().getDimensionPixelSize(R.dimen.x500), getResources().getDimensionPixelSize(R.dimen.x500));
        controlOrientationView = new ControlOrientationView(this,0,0, getResources().getDimensionPixelSize(R.dimen.x500), getResources().getDimensionPixelSize(R.dimen.x500));

        RelativeLayout.LayoutParams layoutParamsMove = new RelativeLayout.LayoutParams(getResources().getDimensionPixelSize(R.dimen.x500), getResources().getDimensionPixelSize(R.dimen.y500));
        layoutParamsMove.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        layoutParamsMove.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        layoutParamsMove.setMargins(getResources().getDimensionPixelSize(R.dimen.x40), 0,0,getResources().getDimensionPixelSize(R.dimen.y40));
        controlMoveView.setLayoutParams(layoutParamsMove);
        controlMoveView.setBackgroundResource(R.mipmap.move_control_10);
        controlMoveView.setOnTouchControlListener(new ControlMoveView.OnTouchControlListener() {
            @Override
            public void onControl(double tankMoveOrientation, float tankOrientation, int type) {
                contentView.refreshTankBody(tankMoveOrientation,tankOrientation,type);
            }
        });

        RelativeLayout.LayoutParams layoutParamsOrientation = new RelativeLayout.LayoutParams(getResources().getDimensionPixelSize(R.dimen.x500), getResources().getDimensionPixelSize(R.dimen.y500));
        layoutParamsOrientation.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        layoutParamsOrientation.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        layoutParamsOrientation.setMargins(0, 0,getResources().getDimensionPixelSize(R.dimen.x40),getResources().getDimensionPixelSize(R.dimen.y40));
        controlOrientationView.setLayoutParams(layoutParamsOrientation);
        controlOrientationView.setBackgroundResource(R.mipmap.move_control_10);
        controlOrientationView.setOnTouchControlListener(new ControlOrientationView.OnTouchControlListener() {
            @Override
            public void onControl(double tankMoveOrientation, float tankOrientation, int type) {
                contentView.refreshTankBore(tankOrientation);
            }
        });


        contentLayout = findViewById(R.id.activity_main_content_rl);
        contentLayout.addView(controlMoveView);
        contentLayout.addView(controlOrientationView);
    }
}
